$(function(){
  let categoryid = getQueryString('categoryid');
  let productid = getQueryString('productid');
  let title = getQueryString('name')
  let $sign = $('.sign');
  let titleStr = `<a href="" class="sign">${title}></a>`
  $sign.after(titleStr);
  let $main = $('#main');
  let $comment = $('.comment');
  let commentStr = ''
  let contentStr = '';
  $.ajax({
    type : 'GET',
    url : 'http://chst.vip:1234/api/getproduct?productid=' + productid,
    async : false,
    dataType : 'json',
    success : function(res){
      let r = res.result[0];
      console.log(r);
      let regExp = /^<[^<]+\s+src="([^''""]*)"/
      let imgUrl = r.productImg.match(regExp)
      console.log(imgUrl);
      contentStr = `
      <div class="info">
        <div class="pic">
          <img src="${imgUrl[1]}" alt="">
        </div>
      <div class="title">${r.productName}</div>
      <div class="count">
        <div class="row">
          <div>
            <span>当前最低</span>
            <span>¥6000</span>
          </div>
          <div>
            <span>优选评论</span>
            <span>8266条</span>
          </div>
        </div>
      </div>
    </div>
    <div class="makeprice">
      ${r.bjShop}
    </div>`
      $main.prepend(contentStr)
    }
  })

  $.ajax({
    type : 'GET',
    async : false,
    url : 'http://chst.vip:1234/api/getproductcom?productid=' + productid,
    success : function(res){
      res.result.forEach(element => {
        commentStr += `    <li>
        <div class="up">
          <span>${element.comName}</span>
          <span>${element.comTime}</span>
        </div>
        <div class="on">
          ${element.comContent}
        </div>
        <div class="down">${element.comFrom}</div>
      </li>`
      });
      console.log(commentStr);
      $comment.append(commentStr)
    }
  })
})